Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dw/dual-float-constants #871 +/- ##
===========================================================
- Coverage 91.22% 91.20% -0.02%
===========================================================
Files 11 11
Lines 1083 1092 +9
===========================================================
+ Hits 988 996 +8
- Misses 95 96 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Use SpecialFunctions.gamma_inc_dx (SpecialFunctions >= 2.10) for the derivative of gamma_inc with respect to x, and define Dual rules for gamma_inc_dx in both arguments. Derivatives of gamma_inc with respect to a throw an informative ArgumentError instead of a MethodError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devmotion
force-pushed
the
dmw/gamma_inc_dx
branch
from
November 3, 2026 21:56
8038f17 to
37abf54
Compare
If the closed form of the derivative of `gamma_inc` overflows, compute it in log space instead (as proposed in #862). Co-Authored-By: Nathan Chandrasekar <322284620+vera-rubin@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`exp((a - 1) * log(x) - x)` overflows the exponent range of MPFR on Windows for `a = x = 1e10`, which would make the reference NaN. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Alternative to #862, based on JuliaMath/SpecialFunctions.jl#568.
#862 avoids the overflow of
exp(-x) * x^(a - 1) / gamma(a)by computing the x-derivative ofgamma_incin log space, but the cancellation in the exponent makes it inaccurate for largea(relative error ~7e-10 ata = 1e6and ~1e-5 ata = 1e10in Float64; ~16% ata = 1e6in Float32).SpecialFunctions#568 adds a public
gamma_inc_dx(a, x) = x^(a - 1) e^(-x) / Γ(a)(the x-derivative ofgamma_inc(a, x)[1]), computed without cancellation, together with internal helpers for its derivatives inaandx. This PR:SpecialFunctions.gamma_inc_dxfor the derivative ofgamma_inc(a, x, ind)with respect tox, if it is available, and falls back to the current formula otherwise (to be removed once SpecialFunctions >= 2.10 is required);gamma_inc_dxin both arguments (via@define_binary_dual_op, so mixed tags work), which makes nested derivatives ofgamma_incinxaccurate, including atx = 0and at the poles ofdigamma(a);ArgumentErrorfor derivatives ofgamma_incwith respect toa, instead of aMethodErrorfrom SpecialFunctions internals; Duals with zero partials foraare supported.Tests compare first derivatives (Float32 and Float64), gradients, Hessians and nested mixed derivatives against BigFloat references, and cover NaN-safe mode. Tests that require
gamma_inc_dxare guarded onisdefined(SpecialFunctions, :gamma_inc_dx).Dependencies:
gamma_inc_dxand fix ChainRules forgamma_incandloggamma(a, x)JuliaMath/SpecialFunctions.jl#568 (until it is released, CI exercises only the fallback path);floatmin,floatmax,maxintfloatandissubnormalforDualinstances #855: with SpecialFunctions >= 2.10, nested derivatives inxcallfloatminon aDualinstance.Locally (with a stand-in for #855),
test/DualTest.jlandtest/DerivativeTest.jlpass against the SpecialFunctions#568 branch and against SpecialFunctions 2.9.1, with NaN-safe mode on and off, and there are no new method ambiguities.🤖 Generated with Claude Code